#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/12/25 9:25
    Desc  :
--------------------------------------
"""
from flask import request
from functools import wraps

from common.libs.JsonResponseUtils import JsonResponse
from common.libs.JwtUtils import verify_jwt


def check_token(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        accesstoken = request.headers.get('accesstoken')
        if accesstoken:
            if accesstoken is None or accesstoken == '' or verify_jwt(accesstoken) is None:
                return JsonResponse(code = 40004, data = None, message = "accesstoken失效").jsonExit()
            return func(*args, **kwargs)
        else:
            return JsonResponse(code = 40004, data = None, message = "accesstoken失效", errors = f'{e}').jsonExit()
    return wrapper